import type { RouteRecordStringComponent } from '@vben/types';

import { requestClient } from '#/api/request';

/**
 * 获取用户所有菜单
 */
export async function getAllMenusApi(selUserId: string) {
  const menus = await requestClient.post<RouteRecordStringComponent[]>(
    '/sys/user/list/menu',
    {
      selUserId,
    },
  );

  const te = menus.map((item) =>
    Object.assign(item, {
      component: 'BasicLayout',
    }),
  );
  console.log(te);
  return te;

  // vben菜单模板 一级路由组件必须使用BasicLayout
  const menusTemp: RouteRecordStringComponent[] = [
    {
      component: 'BasicLayout',
      meta: {
        order: -1,
        title: '看板',
      },
      name: 'Dashboard',
      path: '/dashboard',
      redirect: '/analytics',
      children: [
        {
          name: 'Analytics',
          path: '/analytics',
          component: '/dashboard/analytics/index',
          meta: {
            affixTab: true,
            title: '分析',
          },
        },
        {
          name: 'Workspace',
          path: '/workspace',
          component: '/dashboard/workspace/index',
          meta: {
            title: '工作区',
          },
        },
      ],
    },
    {
      component: 'BasicLayout',
      meta: {
        icon: 'ic:baseline-view-in-ar',
        keepAlive: true,
        order: 1000,
        title: '呆萌',
      },
      name: 'Demos',
      path: '/demos',
      redirect: '/demos/antd',
      children: [
        {
          name: 'antd',
          path: '/antd',
          component: '/demos/antd/index',
          meta: {
            affixTab: true,
            title: 'antd',
          },
        },
      ],
    },
  ];
  return new Promise<RouteRecordStringComponent[]>((resolve) => {
    resolve(menusTemp);
  });
}
